﻿using _2._12._2015_SmartPhone.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace _2._12._2015_SmartPhone.Controllers
{
    public class HomeController : Controller
    {
        //this is a private variable
        private List<SmartPhone> _smartphones;
        public HomeController()
        {
            _smartphones = GetSmartPhones();
        }
        public ActionResult Index()
        {
            IndexViewModel model = new IndexViewModel();

            model.SmartPhones = _smartphones;

            return View(model);
        }

        private static List<SmartPhone> GetSmartPhones()
        {


            List<SmartPhone> smartphones = new List<SmartPhone>();

            WindowsPhone phone1 = new WindowsPhone();
            phone1.NumberofTiles = 4;
            phone1.MakeCall = true;
            phone1.HasGPS = true;

            SmartPhone phone2 = new iPhone();
            phone2.HasGPS = false;
            phone2.MakeCall = true;

            smartphones.Add(phone1);
            smartphones.Add(phone2);
            return smartphones;
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
        public ActionResult Create()
        {
            CreateViewModel model = new CreateViewModel();


            return View(model);
        }
        //Attributes go above the Action/Class/Method that you are assigning it to. 
        [HttpPost]
        public ActionResult Create(CreateViewModel model)
        {
            _smartphones.Add(new WindowsPhone
            {
                HasGPS = model.HasGPS,
                MakeCall = model.MakeCall,
                NumberofTiles = model.NumberOfTiles

            });

            return RedirectToAction("Index");
        }
    }
}